/*
 * @Description:
 * @Author: chenjiaxin
 * @Date: 2022-06-04 16:46:26
 * @LastEditTime: 2022-06-04 17:17:48
 * @FilePath: \leetcode\1_栈结构\02_十进制转二进制.js
 */
// import { Stack } from "./01_栈的封装.js";
// let s = new Stack();

function dec2bin(decNumber) {
  //===>>> 循环技巧: while用于不知道循环次数 for 循环多用于确定的次数
  let stack = new Stack();

  while (decNumber > 0) {
    // 获取余数 放入栈中
    stack.push(decNumber % 2);
    // 获取整除的结果 作为下一次运行的数字
    decNumber = Math.floor(decNumber / 2);
  }
  let binaryString = "";
  while (!stack.isEmpty()) {
    binaryString += stack.pop();
  }

  return binaryString;
}
let result = dec2bin(100);
console.log(result);
